/*
 * @Descripttion: |
 * @version: 1.0
 * @Author: 王娆
 * @Date: 2020-09-03 20:26:13
 * @LastEditors: 王娆
 * @LastEditTime: 2020-09-04 14:26:19
 */
import axios from 'axios'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

export const baseURL = 'http://47.101.45.245:8878';
const server = axios.create({
  baseURL
})

const whiteList = ['/v1/token','/v1/registry']

server.interceptors.request.use((config) => {
  if (config.url == '/v1/token') {
    return config
  };
  if (!whiteList.includes(config.url)) {
    config.headers.authorization = sessionStorage.getItem('token')
  }
  // 进度条
  Nprogress.start()
  return config
}, (error) => {
  // 对请求错误做些什么
  return Promise.reject(error)
})

// 添加响应拦截器
server.interceptors.response.use((response) => {
  Nprogress.done()
  return response.data
}, (error) => {
  // console.log(error.response)
  const response = error.response
  return Promise.reject(error)
})

export default { ...server }
